
Object.extend(String.prototype, {
    toDDXML : function() {
        return this.inspect(false);
    },
    
  inspect: function(useDoubleQuotes) {
    var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
      var character = String.specialChar[match[0]];
      return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
    });
    return this;
  }    
});

Object.extend(Number.prototype, {
  toDDXML: function() {
    return isFinite(this) ? this.toString() : 'null';
  }
});

Object.extend(Array.prototype, {
  toDDXML: function() {
    Result = '<o c="Array">';
    this.each(function(object) {
      var value = Object.toDDXML(object);
      
      var t = "";
      switch(typeof object) {
          case 'string' : t = "s"; break;
          case 'number' : t = "n"; break;
          case 'boolean': t = "b"; break;
          case 'object' : t = "o"; break;
      }      
      if (value !== undefined) Result += '<i t="' + t + '">' + value + '</i>';
    });
    //return '[' + results.join(',') + ']';
    return Result + '</o>';
  }
});


Object.extend(Object, {

getDDXMLClass : function() {
    return "Object";
},

//Object.prototype.toDDXML = function(object,name) {
toDDXML : function(object,name) {
    if ( typeof name == 'undefined' ) name = "";
    
    var type = typeof object;
    switch(type) {
      case 'undefined':
      case 'function':
      case 'unknown': return;
      case 'boolean': return object.toString();
    }
    if (object === null) return '<o>null</o>';
    if (object.toDDXML) return object.toDDXML();
    if (object.ownerDocument === document) return;
    
    var Result = '<o';
    if ( object.getDDXMLClass ) {
        Result += ' c="' + object.getDDXMLClass() + '"';
    }
    Result += '>';
    
    for (var property in object) {
      if ( property == 'transient' || object.transient && object.transient.indexOf( property ) >= 0 ) {
        continue;
      }
      
      var value = Object.toDDXML( object[property], property );
      if ( value !== undefined ) 
      {
          var type = typeof object[property];
          var t = "";
          switch(type) {
              case 'string' : t = "s"; break;
              case 'number' : t = "n"; break;
              case 'boolean': t = "b"; break;
              case 'object' : t = "o"; break;
          }
          
          Result += '<a t="' + t + '" n="' + property + '">' + value + '</a>';
      }
    }
    Result += '</o>';
    
    return( Result );
}

});

//Object.prototype.transient = new Array();

var MapplUtils = new TMapplUtils();
 
function TMapplUtils()
{
    this.objectToXML            = objectToXML;
    
/*******************************************************************************
* objectToXML
*******************************************************************************/
function objectToXML( aObject ) 
{
    Result = "";
    if ( typeof aObject == 'object' )
       Result = internalObjectToXML( aObject, "object" );
   
    //alert( Result ); 
    return( Result );
}

/*******************************************************************************
* internalObjectToXML
*******************************************************************************/
function internalObjectToXML(object, objectName) 
{
    if (object === null) 
    {
        return "<" + objectName + "/>";
    }
        
    if ( object.ownerDocument === document ) 
    {
        return( "" );
    }
   
   //var result = "<object oname=\"" + escape(objectName) + "\"" ;
    var result = "<" + objectName;
    for (var name in object) 
    {
        var value = object[name] ;
        switch (typeof value) 
        {
           default : continue ;
           case 'string': result += " " + name + "=\"" + escape(value) + "\"" ; break ;
           case 'number':
           case 'boolean': result += " " + name + "=\"" + escape(value.toString()) + "\"" ; break ;
        }
    }
    result += ">" ;
    for (var name in object) 
    {
        var value = object[name] ;
        if (value !== object) 
        {
            switch (typeof value) 
            {
               case 'object': result += internalObjectToXML(value, name);
            }
        }
    }
    //result += "</object>";
    result += "</" + objectName + ">";
    return result;
}

} // end MapplUtils